<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      
    </el-form>
    <el-row :gutter="10" class="mb8"  style="text-align: center;font-size: 50px;" > 
      {{this.queryParams.ftDept}} 分摊情况表
 </el-row>
 <el-row type="flex" justify="end">
    <el-col :span="3" style="font-size: 50px; color: red;">
      内部资料
    </el-col>
  </el-row>
    <el-row :gutter="10" class="mb8">
      
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="JyjcBsExpensesList" @selection-change="handleSelectionChange" max-height="850">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="年" align="center" prop="year" />
      <el-table-column label="月份" align="center" prop="yf" />
      <el-table-column label="部门" align="center" prop="deptname" />
      <el-table-column label="经济科目" align="center" prop="economicKm" />
      <el-table-column label="包含的费用" align="center" prop="expenseType" />
      <el-table-column label="部所" align="center" prop="ftDept" />
      <el-table-column label="分摊金额" align="center" prop="moneys" />

    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改部所分摊情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="年" prop="year">
          <el-input v-model="form.year" placeholder="请输入年" />
        </el-form-item>
        <el-form-item label="月份" prop="yf">
          <el-input v-model="form.yf" placeholder="请输入月份" />
        </el-form-item>
        <el-form-item label="部门" prop="deptname">
          <el-input v-model="form.deptname" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="部门编码" prop="deptcode">
          <el-input v-model="form.deptcode" placeholder="请输入部门编码" />
        </el-form-item>
        <el-form-item label="经济科目" prop="economicKm">
          <el-input v-model="form.economicKm" placeholder="请输入经济科目" />
        </el-form-item>
        <el-form-item label="部所" prop="ftDept">
          <el-input v-model="form.ftDept" placeholder="请输入部所" />
        </el-form-item>
        <el-form-item label="分摊金额" prop="moneys">
          <el-input v-model="form.moneys" placeholder="请输入分摊金额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJyjcBsExpenses, getJyjcBsExpenses, delJyjcBsExpenses, addJyjcBsExpenses, updateJyjcBsExpenses } from "@/api/system/JyjcBsExpenses"

export default {
  name: "JyjcBsExpenses",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 部所分摊情况表格数据
      JyjcBsExpensesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        economicKm: null,
        expenseType: null,
        ftDept: null,
        moneys: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    const query = this.$route.query;
    this.queryParams.year=query.year;
    this.queryParams.yf=query.yf;
    this.queryParams.ftDept=query.ftDept;
    this.getList()
  },
  methods: {
    /** 查询部所分摊情况列表 */
    getList() {
      this.loading = true
      listJyjcBsExpenses(this.queryParams).then(response => {
        this.JyjcBsExpensesList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        economicKm: null,
        expenseType: null,
        ftDept: null,
        moneys: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.year)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加部所分摊情况"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const year = row.year || this.ids
      getJyjcBsExpenses(year).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改部所分摊情况"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.year != null) {
            updateJyjcBsExpenses(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addJyjcBsExpenses(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const years = row.year || this.ids
      this.$modal.confirm('是否确认删除部所分摊情况编号为"' + years + '"的数据项？').then(function() {
        return delJyjcBsExpenses(years)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/JyjcBsExpenses/export', {
        ...this.queryParams
      }, `JyjcBsExpenses_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
